package com.common.base.tools.extend

import android.os.Build
import android.text.Html
import androidx.annotation.ColorRes
import androidx.annotation.DimenRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.text.HtmlCompat
import com.common.base.tools.utils.ApplicationUtils

/**
 * Created by zsf on 2021/1/11 14:47
 * ******************************************
 * * 资源扩展
 * ******************************************
 */
fun stringRes(@StringRes stringRes: Int) = ApplicationUtils.context().getString(stringRes)

fun drawableRes(@DrawableRes drawableRes: Int) = ApplicationUtils.context().resources.getDrawable(drawableRes)

fun colorRes(@ColorRes colors: Int) = ApplicationUtils.context().resources.getColor(colors)

fun dimenRes(@DimenRes dimen: Int) = ApplicationUtils.context().resources.getDimensionPixelOffset(dimen)

@Suppress("DEPRECATION")
fun String.renderHtml(): String =
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M)
        Html.fromHtml(this, HtmlCompat.FROM_HTML_MODE_COMPACT).toString()
    else Html.fromHtml(this).toString()

fun getResourceMipmap(imageName: String?): Int {
    return ApplicationUtils.context().resources.getIdentifier(imageName, "mipmap", ApplicationUtils.context().packageName)
}
fun getResourceDrawable(imageName: String?): Int {
    return ApplicationUtils.context().resources.getIdentifier(imageName, "drawable", ApplicationUtils.context().packageName)
}

